package routes

//引用的时候用路径，使用的时候用包名
import (
	version1 "server/api/v1"
	"server/middleware"

	"github.com/gin-gonic/gin"
)

func useVersion1(v1 *gin.RouterGroup) {
	v1.Use()
	//Flag:不需要token
	{
		v1.GET("/getcategories", version1.GetAllcategory)
		v1.GET("/getallarticle", version1.GetAllArticles)
		v1.GET("/getonearticle/:id", middleware.FlowSetter(), version1.GetOneArticle) //流量统计
		v1.GET("/getcategoryarticle/:cate", version1.GetCategoryArticle)
		v1.GET("getcommentofarticle/:id/:pagenum", version1.GetCommentOfArticle)
		v1.GET("/getnumofcomment/:id", version1.GetNumbOfComment)
		v1.GET("/searchblog/:keyword", version1.SearchBlog)
		v1.GET("/timestamp", version1.GetTimeStamp)
		v1.GET("/gettodychat",version1.GetTodayChat)

		v1.POST("postcomment/:id", version1.PostComment)
	}
	//Flag:只需要token
	var normal = v1.Group("/").Use(middleware.JsonWebToken())
	{
		normal.GET("/hoststatus", version1.Gethostinfo)
		normal.GET("/info", version1.Info)
		normal.GET("/getalluser", version1.GetAllUser)

		normal.DELETE("/deleteuser/:id", version1.DeleteUser)
	}
	//Flag:需要token和超级管理员权限
	var hight = v1.Group("/").Use(middleware.JsonWebToken(), middleware.RouteRole(2))
	{
		hight.GET("/getalladmin", version1.GetAllAdmin)

		hight.POST("/addcategory", version1.AddCategory)
		hight.POST("/uploadarticle", version1.UploadArticle)
		hight.POST("/addadmin", version1.AddAdmin)

		hight.PUT("/updataarticle", version1.UpdatArticle)
		hight.PUT("/editcatrgory", version1.EditCategory)
		hight.PUT("/updataadmin", version1.UpdataAdmin)

		hight.DELETE("/deletecategory", version1.DeleteCategory)
		hight.DELETE("/deletearticle/:id", version1.DeleteArticle)
		hight.DELETE("deleteadmin/:id", version1.DeleteAdmin)
	}
	
}
